// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  globalData: {
    userInfo: null
  },
  // 创建全局事件总线  
eventBus: {    
  events: {},    
  on(event, callback) {      
  if (!this.events[event]) this.events[event] = [];      
  this.events[event].push(callback);    
  },    
  off(event, callback) {      
  if (!this.events[event]) return;      
  const index = this.events[event].indexOf(callback);      
  if (index !== -1) this.events[event].splice(index, 1);    
  },    
  emit(event, data) {      
  if (!this.events[event]) return;      
  this.events[event].forEach(callback => callback(data));    
  }  
  },
})
